﻿#include <iostream>
#include <memory>

class Node;
using NodePtr = std::shared_ptr<Node>;

class Node {
public:
    std::string name;
    std::weak_ptr<Node> next;  // 改成 weak_ptr 避免循环引用

    Node(const std::string& name) : name(name) {
        std::cout << name << " create\n";
    }
    ~Node() {
        std::cout << name << " xiaohui\n";
    }
};

int main() {
    NodePtr a = std::make_shared<Node>("A");
    NodePtr b = std::make_shared<Node>("B");

    a->next = b;
    b->next = a; // 如果这里是 shared_ptr，会造成循环引用

    return 0;
}
